<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page contentType="text/html;charset=utf-8" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>新闻管理系统 - 后台登录</title>
    <link rel="stylesheet" href="<c:url value="/resources/css/admin-style.css"/>">
</head>
<body class="login-body">
<div class="login-container">
    <div class="login-box">
        <h2 class="login-title">新闻管理系统</h2>
        <p class="login-subtitle">管理员登录</p>
        <form id="login-form" class="login-form" method="post">
            <div class="form-group">
                <label for="username" class="form-label">用户名</label>
                <input type="text" id="username" name="username" class="form-input" placeholder="请输入用户名" required>
            </div>
            <div class="form-group">
                <label for="password" class="form-label">密码</label>
                <input type="password" id="password" name="password" class="form-input" placeholder="请输入密码"
                       required>
            </div>
            <button type="button" class="login-btn">登录</button>
        </form>
    </div>
</div>
<script src="<c:url value="/resources/js/jquery-3.7.1.min.js"/>"></script>
<script>
    $("button[type='button']").on("click",function () {
        $(document).ready(function () {
            $.ajax({
                url: "/user/login",
                method: 'post',
                data: {
                    username: $("input[name='username']").val(),
                    password: $("input[name='password']").val()
                },
                success: function (data) {
                    if (data === 0) {
                        alert("用户名或密码错误");
                    } else if (data === 1) {
                        location.href = "/dashboard"
                    } else if (data === 2) {
                        alert("你没有权限登录后台，请联系管理员")
                    } else if(data===-1){
                        alert("你的账号已被禁用，请联系管理员")
                    }
                },
                error: function (error) {
                }
            });
        });
    });
</script>
</body>
</html>